import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

public class MainClass {
	public static void main(String[] args) {
		Person person1 = Person.getPerson();
		person1.setName("test");
		System.out.println(person1.getName());

		Person person2 = Person.getPerson();
		System.out.println(person1 == person2);

		Person2 person22 = Person2.getPerson();
		System.out.println(person22);
		person22.setName("test");
		final Person2 person23 = Person2.getPerson();
		System.out.println(person23);
		System.out.println(person23.getName());
		final CyclicBarrier barrier = new CyclicBarrier(100, new Runnable() {
			public void run() {
				System.out.println(Thread.currentThread().getName());
			}
		});
		for(int i=0;i<100;i++) {
			new Thread(new Runnable() {
				
				public void run() {
					try {
						System.out.println(Thread.currentThread().getName()+"wainting...");
						barrier.await();
						
						Person2 person12 = Person2.getPerson();
						System.out.println(person12);
					} catch (InterruptedException e) {
						e.printStackTrace();
					} catch (BrokenBarrierException e) {
						e.printStackTrace();
					}
				}
			}).start();
		}
		Person2 person12 = Person2.getPerson();
		System.out.println(person12);
	}
}
